//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
// var qqmapsdk;
var userType = '';
// var Isshow = false;
// var Isshow1 = false;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 授权
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    powerFlag: false,
    phoneFlag: true,
    code: 'authMSG',
    time: null,//定时器
    imgUrl: '',
    // 轮播
    swiperImgUrls: [],
    // 功能图标
    icons: [],
    four: [],
    longFour: [],
    // 10个功能
    tenArr: [{
      href: "/packageA/tasks/tasks",
      Images: "",
      name: "任务中心"
    },
    {
      // href: "/packageA/bar/bar",
      href: "",
      Images: "",
      name: "邦吧"
    },
    {
      href: "/packageA/merchantsin/merchantsin",
      Images: "",
      name: "商户入驻"

    },
    {
      href: "/packageA/businessCode/businessCode",
      Images: "",
      name: "店铺码"

    },
    {
      href: "/packageA/callBack/callBack",
      Images: "",
      name: "投诉"
    },
    {
      href: "/packageA/gongGao/gongGao",
      Images: "",
      name: "公告"

    },
    {
      href: "",
      Images: "",
      name: "客户管理"
    },
    {
      href: "/packageA/shoppingCart/shoppingCart",
      Images: "",
      name: "购物车"
    },
    {
      href: "/packageA/myProduct/myProduct",
      Images: "",
      name: "收银机"
    },
    {
      href: "/packageA/makerDetail/makerDetail",
      Images: "",
      name: "创客中心"
    }
    ],
    // 10个功能
    tenBrr: [{
      href: "",
      Images: "",
      name: "易直播"
    },
    {
      href: "/packageA/ziXun/ziXun",
      Images: "",
      name: "部落资讯"
    },
    {
      href: "",
      Images: "",
      name: "数据总览"
    },
    {
      href: "/packageA/yiyishipin/yiyishipin",
      Images: "",
      name: "易易视频"
    },
    {
      href: "/packageA/yiyicredit/yiyicredit?SJID=" + wx.getStorageSync('uid'),
      Images: "",
      name: "易易信用"
    },
    {
      href: "/packageA/merchantlist/merchantlist",
      Images: "",
      name: "客户公海"
    },
    {
      href: "/packageA/Business/Business",
      Images: "",
      name: "商务合作"
    },
    {
      href: "/packageA/class/class",
      Images: "",
      name: "易课堂"
    },
    {
      href: "/packageA/daziyuan/daziyuan",
      Images: "",
      name: "大资源"
    },
    {
      href: "/packageA/sjgle/sjgle",
      Images: "",
      name: "企业用户"
    },
    ],
    //精品服务
    goodquality: [{
      href: "/packageA/jiajuchanpin/jiajuchanpin",
      img: "",
      name: `家居产品`
    },
    {
      href: "/packageA/meizhuanghufu/meizhuanghufu",
      img: "",
      name: "美妆护肤"
    }
    ],
    recommondGoodData: [],
    hotGoodData: [],
    newGoodData: [],
    GetHomeTypesList: [],
    // 上拉加载数组
    onReachBottomData: [],
    resultMsg: "",
    state: "",
    // 轮播设置
    indicatorDots: true,
    autoplay: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    indicatorActiveColor: "#fff",
    // 页数
    pageIndex: 1,
    // 控制搜索弹出
    searchFlag: false,
    uid: "",
    // 滚动条新闻
    scrollNews: [],
    // 会员海报图
    members: [],
    // 推荐产品 新店入驻
    four: [],
    // 精品服务
    boutique: [],
    //  品质好货
    goodquality: [],
    // 刷新
    businessId: 0,
    BusinessIsFinishEnter: "",
    Buyers: 0,//是否有未支付邮费
    Seller: 0,//判断是否有新订单
    myTimer: "",
    showTop: true,
    searchScrollList: [],//搜索框滚动数据。
  },


  // 判断新订单
  newOrder() {
    clearInterval(this.data.myTimer)
    var that = this;
    var uid = this.data.uid;
    wx.request({
      url: baseJs.api_Order + "GetOrderPostageStatus/" + '?' + "UID=" + uid,
      success: res => {
        console.log(res);
        if (res.data.ResultFlag == 1) {
          // 卖家订单邮费提示
          if (res.data.ResultData.Seller == "1") {
            wx.showModal({
              title: '提示',
              content: '您有订单需要处理，请前往查看!',
              showCancel: true,
              cancelText: "取消",
              cancelColor: "#000000",
              confirmText: "立即处理",
              confirmColor: "#576B95",
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: "/packageA/myOrder2/myOrder2?type=1",
                  })
                } else if (res.cancel) {
                }
              }
            })
          }
          // 买家
          if (res.data.ResultData.Buyers == "1") {
            wx.showModal({
              title: '温馨提示',
              content: '您有订单尚未支付邮费哟!',
              showCancel: true,
              cancelText: "取消",
              cancelColor: "#000000",
              confirmText: "立即处理",
              confirmColor: "#576B95",
              success(res) {
                if (res.confirm) {
                  wx.navigateTo({
                    url: '/packageA/myOrder/myOrder?type=1',
                  })
                } else if (res.cancel) {
                }
              }
            })
          }
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var uid = '';
    userType = wx.getStorageSync('userType');
    var showDialog = wx.getStorageSync('showDialog');
    var BusinessIsFinishEnter = wx.getStorageSync('BusinessIsFinishEnter');
    this.setData({
      BusinessIsFinishEnter: BusinessIsFinishEnter,
    })

    if (showDialog != '1') {
      wx.showModal({
        title: '提示',
        content: '本软件尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更有个性化的服务，本软件会按照本隐私权政策的规定使用和披露您的个人信息。但本软件将以高度的勤勉、审慎义务对待这些信息。除本隐私权政策另有规定外，在未征得您事先许可的情况下，本软件不会将这些信息对外披露或向第三方提供。本软件会不时更新本隐私权政策。您在同意本软件服务使用协议之时，即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本软件服务使用协议不可分割的一部分!你可以在APP内，关于我们里面查看隐私政策及用户注册协议。',
        showCancel: false
      })
      wx.setStorageSync('showDialog', '1');
    }
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetIsServers"),
      success: function (res) {
        var ResultData = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        if (ResultData.Status == 0) {
          that.setData({
            Isshow: true,
            Isshow1: false,
            IsshowUrlString: ResultData.test1,
          })
          // console.log(IsshowUrlString);
        } else {
          that.setData({
            Isshow: false,
            Isshow1: true,
          })
          uid = wx.getStorageSync('uid');
          BusinessIsFinishEnter = wx.getStorageSync('BusinessIsFinishEnter');
          that.setData({
            uid: uid,
            BusinessIsFinishEnter: BusinessIsFinishEnter,
          })

          if (uid) {
            that.GetUserInfoByIDs();
          }
          that.GetTribeHeadlines();
          that.GetAdvertisingByTypeID();
          that.GetIcon();
          that.GetHomeData();
          that.GetHomeTypesList();
          // 获取搜索滚动的数据
          that.GetSearchGoodsScrollData()
          // 上拉加载
          that.GetHomeGoodList();
          // this.getPhoneNumber();
          // that.GetMessage();
        }
      }
    })
  },

  onShow: function () {
    this.newOrder()
  },

  //刷新
  onRefresh() {
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading({
      backgroundImage: '/images/ren5.png',
      title: '正在刷新...',
      show: true,
      // text: '下拉刷新',
      color: "#000000",
      shadow: 5
    });
    //显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
    wx.showLoading({
    })
    this.getData();
  },
  //网络请求，获取数据
  getData() {
    wx.request({
      url: '',
      //网络请求执行完后将执行的动作
      complete(res) {
        //隐藏loading 提示框
        wx.hideLoading();
        //隐藏导航条加载动画
        wx.hideNavigationBarLoading();
        //停止下拉刷新
        wx.stopPullDownRefresh();
      }
    })
  },
  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {
    //调用刷新时将执行的方法
    this.onRefresh();
  },
  //  推荐产品 新店入驻
  TypesListTap: function (e) {
    var that = this;
    var uid = this.data.uid;
    if (e.currentTarget.dataset.type == 1) {
      wx.navigateTo({
        url: '/packageA/shoppingCart/shoppingCart',
      })
    } else if (e.currentTarget.dataset.type == 2) {
      wx.navigateTo({
        url: '/packageA/sjgle/sjgle',
      })
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.data.pageIndex++;
    this.GetHomeGoodList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '易易部落',
      path: '/pages/index/index',
      success: function (res) {
        wx.showToast({
          title: "转发成功",
          icon: 'none',
          duration: 1000
        });
      },
      fail: function (res) {
        wx.showToast({
          title: "转发失败",
          icon: 'none',
          duration: 1000
        });
      }
    }
  },
  // 授权
  powerTap: function () {
    this.setData({
      powerFlag: !this.data.powerFlag,
    })
  },
  getUserInfo: function (e) {
    var that = this;
    var uid = this.data.uid;
    // console.log(e);
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      hasUserInfo: true,
    })
  },
  // 轮播
  GetAdvertisingByTypeID: function () {
    var that = this;
    var swiperImgUrls = this.data.swiperImgUrls;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetAdvertisingByTypeID&TypeID=1&City=&Area="),
      success: function (res) {
        swiperImgUrls = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        console.log(swiperImgUrls);
        that.setData({
          swiperImgUrls: swiperImgUrls
        })
      }
    })
  },
  // 轮播的点击
  LunBoClick(e) {
    console.log(e);
    var value = (e.currentTarget.dataset.value)
    var src = encodeURIComponent(value.LinkUrl)
    if (value.LinkUrl != 0 && value.LinkUrl != '') {// 跳转内嵌
      wx.navigateTo({
        url: "/packageA/cooperate/cooperate?src=" + src,
      })
    } else if (value.linkGoodsId != 0 && value.linkGoodsId != '') { //跳转商品详情
      wx.navigateTo({
        url: '/packageA/goodsDetail/goodsDetail?goodsId=' + value.linkGoodsId,
      })
    } else { //跳转店铺
      wx.navigateTo({
        url: '/packageA/goodsDetail/goodsDetail?businessId=' + value.linkBusinessId
      })
    }
  },
  // 点击功能
  businessControlTap: function (e) {
    var index = e.currentTarget.dataset.index;
    var that = this;
    var tenArr = this.data.tenArr;
    console.log(index);
    if (index == 5) {
      wx.navigateTo({
        url: that.data.tenArr[index].href,
      })
    } else if (app.isLogin()) {

      wx.navigateTo({
        url: that.data.tenArr[index].href,
      })
      if (index == '1' || index == '6') {
        wx.showToast({
          title: "该功能暂未开放！",
          icon: 'none',
          duration: 1000
        });
      }

      if (userType == 0) {
        wx.showModal({
          title: '提示',
          content: '您未成为商户,暂不可使用该功能,请先去升级账户！',
          showCancel: false
        })
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
        }, 800)
        // 运营中心
        tenArr[2].href = "";
        tenArr[2].name = "商户入驻";
        tenArr[3].href = "";
        tenArr[3].name = "店铺码";

      } else if (userType == 1) {
        // 商家
        // tenArr[2].href = "/packageA/merchantsin/merchantsin";
        // tenArr[2].name = "商户入驻";
        tenArr[3].href = "/packageA/businessCode/businessCode";
        tenArr[3].name = "店铺码";
      } else if (userType == 2) {
        // 普通用户
        tenArr[2].href = "";
        tenArr[2].name = "商户入驻";
        tenArr[3].href = "";
        tenArr[3].name = "店铺码";
        wx.showModal({
          title: '提示',
          content: '您未成为商户,暂不可使用该功能,请先去升级账户！',
          showCancel: false
        })
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
        }, 800)
      }
    }
  },

  // 点击功能A
  businessControlTapA: function (event) {
    var that = this;
    var tenBrr = that.data.tenBrr;
    var index = event.currentTarget.dataset.index;
    console.log(index);
    if (index == 4 || index == 5 || index == 9) { //判断登录
      if (app.isLogin()) {
        wx.navigateTo({
          url: tenBrr[index].href,
        })
      }
    } else {
      tenBrr[3].href = "/packageA/yiyishipin/yiyishipin"
      wx.navigateTo({
        url: tenBrr[index].href,
      })
      if (index == '0') {
        wx.showToast({
          title: "该功能暂未开放！",
          icon: 'none',
          duration: 1000
        });
      } else if (index == "2") { //判断是否可进入数据总览
        var IsAgentBigAreaManager = app.globalData.IsAgentBigAreaManager
        var IsAgentHeHuoRen = app.globalData.IsAgentHeHuoRen
        var IsPartner = app.globalData.IsPartner
        if (IsAgentBigAreaManager == "1" || IsAgentHeHuoRen == "1" || IsPartner == "1" || userType == "0"){
          wx.navigateTo({
            url: '../../packageB/overview/overview',
          })
        }else{
          wx.showToast({
            title: '暂无权限 !',
            icon:'none',
            duration:1000
          })
        }
      }
    }
  },

  // 功能图标
  GetIcon: function () {
    var that = this;
    var uid = this.data.uid;
    var icons = this.data.icons;
    var four = this.data.four;
    var longFour = this.data.longFour;
    var tenArr = this.data.tenArr;
    var tenBrr = this.data.tenBrr;
    var members = this.data.members;
    var boutique = this.data.boutique;
    var goodquality = this.data.goodquality;
    var TypesList = this.data.TypesList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetIcon&UID=" + uid),
      success: function (res) {
        console.log(JSON.parse(baseJs.decryUrl(res.data)).ResultData);
        icons = JSON.parse(baseJs.decryUrl(res.data)).ResultData.shigexiaotubiao;
        four = JSON.parse(baseJs.decryUrl(res.data)).ResultData.toutiaoxiasigetu;
        longFour = JSON.parse(baseJs.decryUrl(res.data)).ResultData.tesetuijianxiaochangtu;
        members = JSON.parse(baseJs.decryUrl(res.data)).ResultData.CenterPoster;
        boutique = JSON.parse(baseJs.decryUrl(res.data)).ResultData.jingpinfuwu;
        goodquality = JSON.parse(baseJs.decryUrl(res.data)).ResultData.jingpindianpu;
        TypesList = JSON.parse(baseJs.decryUrl(res.data)).ResultData.TuiJianAndXinDian;
        var MemBers = members[0].Images;
        var tenArrList = [];
        for (var j = 0; j < icons[0].length; j++) {

          if (userType == 0) {
            // 运营中心
            tenArr[j].Images = icons[0][j].ImagesToAgent;
            if (icons[0][j].ImagesToAgent == "") {
              tenArr[j].Images = icons[0][j].Images;
            }
            tenArr[2].href = "/packageA/merchantsin/merchantsin";
            tenArr[2].name = "商户入驻";
            tenArr[3].href = "/packageA/businessCode/businessCode";
            tenArr[3].name = "店铺码";
          } else if (userType == 1) {
            // 商家
            tenArr[j].Images = icons[0][j].ImagesToBusiness;
            if (icons[0][j].ImagesToBusiness == "") {
              tenArr[j].Images = icons[0][j].Images;
            }
            tenArr[2].href = "/packageA/merchantsin/merchantsin";
            tenArr[2].name = "商户入驻";
            tenArr[3].href = "/packageA/businessCode/businessCode";
            tenArr[3].name = "店铺码";
          } else {
            tenArr[j].Images = icons[0][j].ImagesToPerson;
            if (icons[0][j].ImagesToPerson == "") {
              tenArr[j].Images = icons[0][j].Images;
            }
            tenArr[2].href = "/packageA/merchantsin/merchantsin";
            tenArr[2].name = "商户入驻";
            tenArr[3].href = "/packageA/businessCode/businessCode";
            tenArr[3].name = "店铺码";

          }
        }
        tenArrList = [].concat(tenArr);

        // 7个
        var tenBrrList = [];
        for (var j = 0; j < icons[1].length; j++) {
          if (userType == 0) {
            // 运营中心
            tenBrr[j].Images = icons[1][j].ImagesToAgent;
            if (icons[1][j].ImagesToAgent == "") {
              tenBrr[j].Images = icons[1][j].Images;
            }
            tenBrr[2].href = "";
            tenBrr[2].name = "数据总览";
            tenBrr[3].href = "";
            tenBrr[3].name = "易易视频";
          } else if (userType == 1) {
            // 商家
            tenBrr[j].Images = icons[1][j].ImagesToBusiness;
            if (icons[1][j].ImagesToBusiness == "") {
              tenBrr[j].Images = icons[1][j].Images;
            }
            tenBrr[2].href = "";
            tenBrr[2].name = "数据总览";
            tenBrr[3].href = "";
            tenBrr[3].name = "易易视频";
          } else {
            tenBrr[j].Images = icons[1][j].ImagesToPerson;
            if (icons[1][j].ImagesToPerson == "") {
              tenBrr[j].Images = icons[1][j].Images;
            }
            tenBrr[2].href = "";
            tenBrr[2].name = "数据总览";
            tenBrr[3].href = "";
            tenBrr[3].name = "易易视频";
          }
        }
        tenBrrList = [].concat(tenBrr);
        that.setData({
          icons: icons,
          four: four,
          longFour: longFour,
          tenArr: tenArrList,
          tenBrr: tenBrrList,
          members: members,
          boutique: boutique,
          goodquality: goodquality,
          TypesList: TypesList,
          MemBers: MemBers,
        })
      }

    })
  },

  // 点击海报图跳转到折扣区页面
  clickToDisconut() {
    var BusinessIsFinishEnter = wx.getStorageSync('BusinessIsFinishEnter');
    if (userType == '1' && BusinessIsFinishEnter == '1') {
      wx.navigateTo({
        url: '/packageA/goodList/goodList',
      })
    } else {
      wx.navigateTo({
        url: '/packageA/disconut/disconut',
      })
    }
  },
  //点击推荐产品跳转到部落优选页面  
  clickToBuluoRecommend(e) {
    var index = e.currentTarget.dataset.index;
    // wx.navigateTo({
    //   url: '/packageA/buluoRecommend/buluoRecommend',
    // })
    if (index == 1) {
      wx.navigateTo({
        url: '/packageA/buluoRecommend/buluoRecommend'
      })
    } else if (index == 2) {
      wx.navigateTo({
        url: "/packageA/goodsquality/goodsquality"
      })
    }
  },
  //点击新店入驻跳转到新店入驻页面
  clickToNewStor() {
    wx.navigateTo({
      url: '/packageA/newStor/newStor',
    })
  },
  //点击精品服务跳转到精品服务详情页里面
  clickToBoutique(e) {
    console.log(e);
    var id = e.currentTarget.dataset.value.LinkOrServicesParam
    var title = e.currentTarget.dataset.value.Title
    wx.navigateTo({
      url: '/packageA/jiajuchanpin/jiajuchanpin?id=' + id + "&title=" + title,
    })
  },
  //点击品质好货跳转到大宗专区详情页里面
  clickToGoodquality() {
    wx.navigateTo({
      url: '/packageA/meizhuanghufu/meizhuanghufu',
    })
  },
  // 首页推荐产品(推荐产品中的部落优选页面)
  GetHomeData: function () {
    var that = this;
    var recommondGoodData = this.data.recommondGoodData;
    var hotGoodData = this.data.hotGoodData;
    var newGoodData = this.data.newGoodData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetHomeData&City=&Area="),
      success: function (res) {
        recommondGoodData = JSON.parse(baseJs.decryUrl(res.data)).ResultData.recommondGoodData;
        hotGoodData = JSON.parse(baseJs.decryUrl(res.data)).ResultData.hotGoodData;
        // newGoodData = JSON.parse(baseJs.decryUrl(res.data)).ResultData.newGoodData;
        that.setData({
          recommondGoodData: recommondGoodData,
          hotGoodData: hotGoodData,
          // newGoodData: newGoodData,
        })

      }
    })
  },
  // 首页推广分类
  GetHomeTypesList: function () {
    var that = this;
    var GetHomeTypesList = this.data.GetHomeTypesList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetHomeTypesList"),
      success: function (res) {
        GetHomeTypesList = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        that.setData({
          GetHomeTypesList: GetHomeTypesList,
        })
        // console.log(GetHomeTypesLis);
      }
    })
  },
  // 上拉加载商品列表
  GetHomeGoodList: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    var pageIndex = this.data.pageIndex;
    var onReachBottomData = this.data.onReachBottomData;
    var resultMsg = this.data.resultMsg;
    var state = this.data.state;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetHomeGoodList&City=&Area=&PageSize=10&PageIndex=" + pageIndex),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        resultMsg = JSON.parse(baseJs.decryUrl(res.data)).ResultMsg;
        for (var i = 0; i < json.length; i++) {
          onReachBottomData.push(json[i])
        }
        that.setData({
          onReachBottomData: onReachBottomData,
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading()
      }
    })
  },
  // 新品特区、热卖潮牌、部落推荐、新店入驻(点击不同页面的跳转)
  fourTap: function (e) {
    var index = e.currentTarget.dataset.index;
    if (index == 0) {
      wx.navigateTo({
        url: "/packageA/newSpecial/newSpecial"
      })
    } else if (index == 1) {
      wx.navigateTo({
        url: "/packageA/hotPopular/hotPopular"
      })
    } else if (index == 2) {
      wx.navigateTo({
        url: "/packageA/buluoRecommend/buluoRecommend"
      })
    } else {
      wx.navigateTo({
        url: "/packageA/newStor/newStor"
      })
    }
  },
  // 扫一扫
  scanTap: function () {
    var uid = this.data.uid;
    // 扫一扫判断是否登录
    wx.scanCode({
      // onlyFromCamera: true,
      success(res) {
        console.log(res);
        if (app.isLogin()) {
          var result = res.result;
          if (result.split("&")[0] == "exchange") {
            wx.request({
              url: baseJs.api + baseJs.encryUrl("method=FinishedExchangeOrder&ConsumerNumber=" + result.split("&")[1]),
              success: function (res) {
                var json = JSON.parse(baseJs.decryUrl(res.data));
                if (json.ResultFlag == 1) {
                  wx.showToast({
                    title: json.ResultMsg,
                    icon: 'none',
                    duration: 1000
                  });
                } else {
                  wx.showToast({
                    title: json.ResultMsg,
                    icon: 'none',
                    duration: 1000
                  });
                }
              }
            })
          } else if (result.split("&")[0] == "YiYiBuLuo+OrderScanPay") {
            wx.navigateTo({
              url: '/packageA/Orderpayment/Orderpayment?orderid=' + result.split("&")[1],
            })
          } else {
            var id = result.split('&')[1].split('&')[0];
            wx.navigateTo({
              url: '/packageA/store/store?businessId=' + id,
            })
            // wx.showModal({
            //   title: '提示',
            //   content: '请选择要进行的操作！',
            //   cancelText: "去店铺",
            //   confirmText: "自由支付",
            //   success: function (res) {
            //     if (res.confirm) {
            //       wx.navigateTo({
            //         url: '/packageA/freePay/freePay?businessId=' + id,
            //       })
            //     } else {
            //       wx.navigateTo({
            //         url: '/packageA/store/store?businessId=' + id,
            //       })
            //     }
            //   },
            // })
          }
        }
      },
      fail(res) {

      },
    })
  },
  // 滚动条新闻
  GetTribeHeadlines: function () {
    var that = this;
    var uid = this.data.uid;
    var scrollNews = this.data.scrollNews;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetTribeHeadlines"),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        // console.log(json)
        for (var i = 0; i < json.length; i++) {
          scrollNews.push(json[i])
        }
        that.setData({
          scrollNews: scrollNews,
        })
        // console.log(scrollNews)
        // wx.setStorageSync('businessId', json[i].ID);
        // console.log(json[i].ID)
      }
    })
  },
  // 点击新闻跳转到详情页面
  newsTap: function (e) {
    if (e.currentTarget.dataset.type == "公告") {
      wx.navigateTo({
        url: '/packageA/newsDetail/newsDetail?id=' + e.currentTarget.dataset.id,
      })
    } else if (e.currentTarget.dataset.type == "新品") {
      wx.navigateTo({
        url: '/packageA/goodsDetail/goodsDetail?goodsId=' + e.currentTarget.dataset.id,
      })
    } else if (e.currentTarget.dataset.type == "商户") {
      wx.navigateTo({
        url: '/packageA/store/store?businessId=' + e.currentTarget.dataset.id,
      })

    } else if (e.currentTarget.dataset.type == "互动") {
      wx.navigateTo({
        url: '/packageA/barDetail/barDetail?id=' + e.currentTarget.dataset.id,
      })
    } else {
      wx.navigateTo({
        url: '/packageA/newsDetail/newsDetail?id=' + e.currentTarget.dataset.id,
      })
    }

  },
  // 获取用户信息
  GetUserInfoByIDs: function () {
    var that = this;
    var uid = this.data.uid;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetUserInfoByIDs&UID=" + uid),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        // console.log(json);
        if (json.ResultFlag == 1) {
          wx.setStorageSync('isAlreadyPasswords', json.ResultData.IsTradePassWord);
        } else {
          // wx.showToast({
          //   title: json.ResultMsg,
          //   icon: 'none',
          //   duration: 2000
          // });
        }

      }
    })

  },
  // 是否显示返回顶部图标
  onPageScroll: function (e) {
    if (e.scrollTop > 600) {
      this.setData({
        showTop: false
      })
    } else {
      this.setData({
        showTop: true
      })
    }
  },
  //返回顶部
  gotop() {
    wx.pageScrollTo({
      duration: 500,
      scrollTop: 0
    })
  },
  //获取搜索框轮播产品数据
  GetSearchGoodsScrollData() {
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetSearchGoodsScrollData"),
      success: (res) => {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        // console.log(json);
        this.setData({
          searchScrollList: json
        })
      }
    })
  }
})